/*
 * Copyright(c) 2018-? the original author[Wien(luweien@aliyun.com)] or authors.
 *
 */
package org.doll.it.web.config;

import java.nio.charset.StandardCharsets;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.client.RestTemplate;

/**
 * RestTemplate配置
 * 
 * @author Wien(luweien@aliyun.com)
 *
 */
@Configuration
public class RestConfig {

	@Bean
	public RestTemplate restTemplate() {
		// index:是RestTemplate默认构造方法中，StringHttpMessageConverter的位置，参考RestTemplate的构造方法源码
		// 修改其编码为UTF-8,解决其中文乱码的问题
		int index = 1;

		RestTemplate rest = new RestTemplate();
		rest.getMessageConverters().set(index, new StringHttpMessageConverter(StandardCharsets.UTF_8));
		return rest;
	}
}
